// javamaps
// Copyright (c) 2010 Maris Ramona
package Core;
import java.util.*;
import java.io.*;

public class Node implements Serializable {
    private ObjectId id_;
    private Coordinates coordinates_;
    private Map<ObjectId, Link> links_;

    public static final double Epsilon = 0.0001; // Eroare max. admisa.

     /*
      * Constructori.
      */
    public Node(ObjectId id, Coordinates coordinates){
        id_ = id;
        coordinates_ = coordinates;
        links_ = new HashMap<ObjectId,Link>();
    }

   public Node(ObjectId id, double latitude, double longitude){
        id_ = id;
        coordinates_ = new Coordinates(latitude, longitude);
        links_ = new HashMap<ObjectId,Link>();
   }
   
    /*
     * Metode publice.
     */

   public ObjectId Id(){ return id_; }
   public void SetId( ObjectId nodeId ){
       id_ = nodeId;
   }
   
   public Coordinates Coordinates(){ return coordinates_;}
   public void SetCoordinates( Coordinates coordinates1 ){
       coordinates_ = coordinates1;
   }

   //Metode ce ofera acces la HashMap-ul links_.
   //Se returneaza HashMap-ul links_.
   public Map<ObjectId,Link> Links(){ return links_;}

   //Se returneaza link-ul cu id-ul primit ca parametru.
   public Link Link(ObjectId id){ return links_.get(id);}

   //Se adauga un link in HashMap-ul links_.
   public void AddLink( Link element ){
        links_.put(element.LinkId(), element);
   }

   //Se verifica daca un link apartine HashMap-ului .
   public boolean ContainsLink(Link element){
        return links_.containsKey(element.LinkId());
   }

   //Se sterge un link din HashMap-ul links_.
   public void DeleteLink( ObjectId id){
        links_.remove(id);
       }

   //Se sterg link-urile din HashMap.
   public void ClearLinks(){
        links_.clear();
   }

   //Se returneaza un iterator pentru HashMap-ul links_.
   public Iterator<Link> Iterator(){
        Collection collection = links_.values();
        Iterator i = collection.iterator();
        return i;
   }
/*
   @Override
   public boolean equals(Object obj){
        if(obj == null) return false;
        if(this == obj) return true;
        if(this.getClass() != obj.getClass()) return false;

        Node node1 = (Node)obj;
        return (Math.abs(node1.nodeId_.Id()- nodeId_.Id()) < Epsilon ) &&
               (Math.abs(node1.nodeCoordinates_.Latitude() - nodeCoordinates_.Latitude()) < Epsilon) &&
               (Math.abs(node1.nodeCoordinates_.Longitude() - nodeCoordinates_.Longitude()) < Epsilon);
   }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + this.nodeId_.Id();
        hash = 59 * hash + (int)(Double.doubleToLongBits(this.nodeCoordinates_.Latitude()) ^
                                (Double.doubleToLongBits(this.nodeCoordinates_.Latitude()) >>> 32));
        hash = 59 * hash + (int)(Double.doubleToLongBits(this.nodeCoordinates_.Longitude()) ^
                                (Double.doubleToLongBits(this.nodeCoordinates_.Longitude()) >>> 32));
        return hash;
    }
*/

   //Pentru debugging.
   @Override
   public String toString(){
        return id_ + "; " + coordinates_;
  }
}

